# -*- coding: UTF-8 -*-
import os
import commands
import sys

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "error parameter"
        sys.exit(-1)
    directorypath = sys.argv[1]
    print directorypath
    filelist = os.listdir(directorypath)
    # print str(filelist)
    print "-----"
    for item in filelist:
        item = directorypath + item
        if not os.path.isfile(item):
            continue
        print item
        result = commands.getoutput("file " + item)
        if result.find("CRLF") == -1:
            print "continue"
            continue
        file = open(item, "rU")
        con = file.read()
        file.close()
        file = open(item, "w")
        file.write(con)
        file.close()
        print commands.getoutput("file " + item)
        print "----end---"
        pass
    print "all end"
